package com.aboverock.common.utils;

import com.aboverock.core.spring.SpringContextHolder;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import sun.misc.MessageUtils;

/**
 * @author Rock Wang
 */
public class MessagesUtil {
    private final static Logger logger = LoggerFactory.getLogger(MessageUtils.class);

    public static String get(String msgKey,String... args ) {
        try {
            Locale locale = LocaleContextHolder.getLocale();
            return SpringContextHolder.getBean(MessageSource.class).getMessage(msgKey, args, locale);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return msgKey;
    }

}
